home *** CD-ROM | disk | FTP | other *** search
- package java.io;
-
- import sun.io.ByteToCharConverter;
- import sun.io.ConversionBufferFullException;
-
- public class InputStreamReader extends Reader {
- private ByteToCharConverter btc;
- // $FF: renamed from: in java.io.InputStream
- private InputStream field_0;
- private static final int defaultByteBufferSize = 8192;
- // $FF: renamed from: bb byte[]
- private byte[] field_1;
- private int nBytes;
- private int nextByte;
-
- public InputStreamReader(InputStream in) {
- this(in, ByteToCharConverter.getDefault());
- }
-
- public InputStreamReader(InputStream in, String enc) throws UnsupportedEncodingException {
- this(in, ByteToCharConverter.getConverter(enc));
- }
-
- private InputStreamReader(InputStream in, ByteToCharConverter btc) {
- super(in);
- this.nBytes = 0;
- this.nextByte = 0;
- this.field_0 = in;
- this.btc = btc;
- this.field_1 = new byte[8192];
- }
-
- public void close() throws IOException {
- synchronized(super.lock) {
- if (this.field_0 == null) {
- return;
- }
-
- this.field_0.close();
- this.field_0 = null;
- this.field_1 = null;
- this.btc = null;
- }
-
- }
-
- private int convertInto(char[] cbuf, int off, int end) throws IOException {
- int nc = 0;
- if (this.nextByte < this.nBytes) {
- try {
- nc = this.btc.convert(this.field_1, this.nextByte, this.nBytes, cbuf, off, end);
- this.nextByte = this.nBytes;
- if (this.btc.nextByteIndex() != this.nextByte) {
- this.malfunction();
- }
- } catch (ConversionBufferFullException var5) {
- this.nextByte = this.btc.nextByteIndex();
- nc = this.btc.nextCharIndex() - off;
- }
- }
-
- return nc;
- }
-
- private void ensureOpen() throws IOException {
- if (this.field_0 == null) {
- throw new IOException("Stream closed");
- }
- }
-
- private int fill(char[] cbuf, int off, int end) throws IOException {
- int nc = 0;
- if (this.nextByte < this.nBytes) {
- nc = this.convertInto(cbuf, off, end);
- }
-
- while(off + nc < end) {
- if (this.nBytes != -1) {
- if (nc > 0 && !this.inReady()) {
- break;
- }
-
- this.nBytes = this.field_0.read(this.field_1);
- }
-
- if (this.nBytes == -1) {
- nc += this.flushInto(cbuf, off + nc, end);
- if (nc == 0) {
- return -1;
- }
- break;
- }
-
- this.nextByte = 0;
- nc += this.convertInto(cbuf, off + nc, end);
- }
-
- return nc;
- }
-
- private int flushInto(char[] cbuf, int off, int end) throws IOException {
- int nc = 0;
-
- try {
- nc = this.btc.flush(cbuf, off, end);
- } catch (ConversionBufferFullException var5) {
- nc = this.btc.nextCharIndex() - off;
- }
-
- return nc;
- }
-
- public String getEncoding() {
- synchronized(super.lock) {
- return this.btc != null ? this.btc.getCharacterEncoding() : null;
- }
- }
-
- private boolean inReady() {
- try {
- return this.field_0.available() > 0;
- } catch (IOException var1) {
- return false;
- }
- }
-
- private void malfunction() {
- throw new InternalError("Converter malfunction (" + this.btc.getCharacterEncoding() + ") -- please submit a bug report via " + System.getProperty("java.vendor.url.bug"));
- }
-
- public int read() throws IOException {
- char[] cb = new char[1];
- return this.read(cb, 0, 1) == -1 ? -1 : cb[0];
- }
-
- public int read(char[] cbuf, int off, int len) throws IOException {
- synchronized(super.lock) {
- this.ensureOpen();
- return this.fill(cbuf, off, off + len);
- }
- }
-
- public boolean ready() throws IOException {
- synchronized(super.lock) {
- this.ensureOpen();
- return this.nextByte < this.nBytes || this.inReady();
- }
- }
- }
-